<?php
/**
 * @version		$Id: install.k2mart.php 25 2010-09-08 15:16:11Z joomlaworks $
 * @package		K2mart
 * @author    JoomlaWorks http://www.joomlaworks.gr
 * @copyright	Copyright (c) 2006 - 2010 JoomlaWorks, a business unit of Nuevvo Webware Ltd. All rights reserved.
 * @license		Commercial - This code cannot be redistributed without permission from Nuevvo Webware Ltd.
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

//Import libraries
jimport('joomla.installer.installer');
jimport('joomla.filesystem.file');

// Load K2mart language file
$lang = &JFactory::getLanguage();
$lang->load('com_k2mart', JPATH_ADMINISTRATOR);

//Install plugins
$db = & JFactory::getDBO();
$status = new JObject();
$status->plugins = array();
$src = $this->parent->getPath('source');

$plugins = &$this->manifest->getElementByPath('plugins');
if (is_a($plugins, 'JSimpleXMLElement') && count($plugins->children())) {

	foreach ($plugins->children() as $plugin) {
		$pname = $plugin->attributes('plugin');
		$pgroup = $plugin->attributes('group');
		$path = $src.DS.'plugins'.DS.$pgroup;
		$installer = new JInstaller;
		$result = $installer->install($path);
		$status->plugins[] = array('name'=>$pname,'group'=>$pgroup, 'result'=>$result);

		$query = "UPDATE #__plugins SET published=1 WHERE element=".$db->Quote($pname)." AND folder=".$db->Quote($pgroup);
		$db->setQuery($query);
		$db->query();
	}
}

//Disable front-end menu link creation
$query = "UPDATE #__components SET `link`='' WHERE `option`='com_k2mart'";
$db->setQuery($query);
$db->query();

//Check for requirements
$mainframe = &JFactory::getApplication();
if(!JFile::exists(JPATH_SITE.DS.'components'.DS.'com_k2'.DS.'k2.php')){
	$mainframe->enqueueMessage(JText::_('K2 was not found on your system'), 'notice');
}
if(!JFile::exists(JPATH_SITE.DS.'components'.DS.'com_virtuemart'.DS.'virtuemart.php')){
	$mainframe->enqueueMessage(JText::_('Virtuemart was not found on your system'), 'notice');
}
?>
<img src="components/com_k2mart/images/logo.png" alt="K2mart <?php echo JText::_('Component'); ?>" align="right" />
<h2><?php echo JText::_('K2mart Installation Status'); ?></h2>
<table class="adminlist">
	<thead>
		<tr>
			<th class="title" colspan="2"><?php echo JText::_('Extension'); ?></th>
			<th width="30%"><?php echo JText::_('Status'); ?></th>
		</tr>
	</thead>
	<tbody>
		<tr class="row0">
			<td class="key" colspan="2"><?php echo 'K2mart '.JText::_('Component'); ?></td>
			<td><strong><?php echo JText::_('Installed'); ?></strong></td>
		</tr>
		<?php if (count($status->plugins)) : ?>
		<tr>
			<th><?php echo JText::_('Plugin'); ?></th>
			<th><?php echo JText::_('Group'); ?></th>
			<th></th>
		</tr>
		<?php foreach ($status->plugins as $key=>$plugin) : ?>
		<tr class="row<?php echo ($key % 2); ?>">
			<td class="key"><?php echo ucfirst($plugin['name']); ?></td>
			<td class="key"><?php echo ucfirst($plugin['group']); ?></td>
			<td><strong><?php echo ($plugin['result'])?JText::_('Installed'):JText::_('Not installed'); ?></strong></td>
		</tr>
		<?php endforeach; ?>
		<?php endif; ?>
	</tbody>
	<tfoot>
		<tr>
			<td colspan="3"></td>
		</tr>
	</tfoot>
</table>
